package com.cyys.modules.system.service.org;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cyys.common.services.RealizeService;
import com.cyys.modules.system.dao.org.OrgUserDao;
import com.cyys.modules.system.model.org.OrgUser;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("orgUserService")
@Transactional(readOnly = true)
public class OrgUserService extends RealizeService<OrgUserDao, OrgUser> {

	/**
	 * 根据机构获取用户
	 * @param page
	 * @param orgId
	 * @return
	 * @
	 */
	public IPage<OrgUser> getByOrgId(Page page, String orgId)  {
		QueryWrapper<OrgUser> qw = new QueryWrapper<>();
		OrgUser orgUser = new OrgUser();
		orgUser.setOrgId(orgId);
		qw.setEntity(orgUser);
		qw.orderByDesc("date_create");
		return dao.selectPage(page,qw);
	}

	public OrgUser getByUserId(String userId) {
		QueryWrapper<OrgUser> qw = new QueryWrapper<>();
		OrgUser orgUser = new OrgUser();
		orgUser.setUserId(userId);
		qw.setEntity(orgUser);
		return dao.selectOne(qw);
	}

}
